// pages/app/fanyin/fanyin.js
var utils = require('../../..//utils/util.js')
const config = require('../../..//utils/config.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    array1: [
      {
        key:"zh",
        form:"中文",
      },
      {
        key:"en",
        form:"英文",
      },
      {
        key:"cht",
        form:"繁体中文",
      },
      {
        key:"kor",
        form:"韩语",
      },
      {
        key:"jp",
        form:"日语",
      },
      {
        key:"ru",
        form:"俄语",
      },
      {
        key:"spa",
        form:"西班牙语",
      },
    ],
    index1: 0,
    index2: 1,
    str:'',
    text:'',
    tools_name:''
  },
  bindPickerChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      index1: e.detail.value
    })
  },
  bindPickerChange1: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      index2: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      tools_name:options.tools_name
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  self: function (e) {
    wx.switchTab({
      url: '../../index/index'
    })
  },
  fy:function(e){
    var str = e.detail.value.str;
    var that = this;
    if(!str){
      wx.showToast({
        title: '不能为空',
        icon: 'none',
        duration: 500
      })
      
    }
    //调用翻译接口
    utils.requests(config.fanyi,{
      q:str,
      to:that.data.array1[that.data.index1].key,
      form:that.data.array1[that.data.index2].key
    },'GET',function(e){
      if(e.data.code !=200){
        wx.showToast({
          title: e.data.msg,
          icon: 'none',
          duration: 1500
        })
      }else{
        console.log(e.data.result)
        that.setData({
          text:e.data.result.trans_result[0].dst
        })
      }
    })

  },
  click:function(e){
    this.setData({
      str: '',
      content:'',
      index:''
    })
  },
})